package com.chinamobile.websocket.websocketdispatcher.distributor.redis;

import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;

import javax.annotation.PostConstruct;

/**
 * @className: RedisMessageListenerInitializer
 * @description 初始化 redis 消息的监听器
 * @author: fanzhijun
 * @date: 2024/1/22
 **/
@RequiredArgsConstructor
public class RedisMessageListenerInitializer {

    private final RedisMessageListenerContainer redisMessageListenerContainer;

    private final RedisMessageDistributor redisWebsocketMessageListener;

    @PostConstruct
    public void addMessageListener() {
        redisMessageListenerContainer.addMessageListener(redisWebsocketMessageListener,
                new PatternTopic(RedisMessageDistributor.CHANNEL));
    }

}